package com.atguigu.datastream.day07;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * ClassName: Flink04_Union
 * Package: com.atguigu.day07
 * Description:
 *             使用Union链接两条流
 * @Author ChenJun
 * @Create 2023/4/14 18:10
 * @Version 1.0
 */
public class Flink04_Union {
    public static void main(String[] args) throws Exception {

        //1. 创建流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //2. 创建两条流
        DataStreamSource<String> wordDStream = env.fromElements("a", "b", "c", "d");

        DataStreamSource<String> numberDStream = env.fromElements("1", "2", "3", "4");

        //TODO 3. 使用Union链接两条流
        DataStream<String> dataStream = wordDStream.union(numberDStream);

        SingleOutputStreamOperator<String> result = dataStream.map(new MapFunction<String, String>() {
            @Override
            public String map(String value) throws Exception {
                return value + "-->chenjun";
            }
        });

        result.print();

        env.execute();

    }
}
